<?php
/**
 * Created by PhpStorm.
 * User: zhangbing
 * Date: 2017/5/20
 * Time: 16:16
 */
namespace app\admin\controller;
use app\models\Models;

class Check extends Base{
    /**
     * 控制器前置操作
     * @return array|bool
     */
    public function _initialize(){
        //没有登录直接跳转到登录页
        if(!cookie('join_login')){
            $this->redirect('login/login');
        }
        // 超级管理员不做权限验证
        if(cookie('join_login') == Models::GROUP_ADMIN){
            return true;
        }
        // 其他用户以下方法不做验证
        if(request()->action() == 'index' || request()->action() == 'logout' || request()->action() == 'login' || request()->action() == 'main'){
            return true;
        }
        //验证权限
        $auth = new Auth();
        if ($auth->check(request()->module() . '/' . request()->controller() . '/' . request()->action(), cookie('join_login'))) {
            return true;
        } else {
            if(request()->isAjax()){
                exit(json_encode(self::formatResult(1003,'抱歉，您不具备该权限!')));
            }
$html=<<<html
    <html>
    <head>
    <meta charset="utf-8">
    <link rel="stylesheet" type="text/css" href="/static/admin/css/H-ui.min.css" />
    <link rel="stylesheet" type="text/css" href="/static/admin/css/H-ui.admin.css" />
    <script type="text/javascript" src="/static/admin/js/jquery.min.js"></script>
    <script type="text/javascript" src="/static/admin/js/layer.js"></script>
    </head>
    <body>
    <script type="text/javascript">
        $(function(){
          setInterval("closeWindow()",1500);
            layer.msg('抱歉，您不具备该权限！',{icon: 7,time:1500});
          });
        function closeWindow(){
            var index = parent.layer.getFrameIndex(window.name);
            parent.layer.close(index);
       }
    </script>
    </body>
    </html>
html;
            echo $html;exit;
        }
    }
}